package com.starry.module.system.core.dict.controller.admin;

import cn.hutool.http.HttpStatus;
import com.starry.core.common.domain.R;
import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.tenant.core.aop.TenantIgnore;
import com.starry.core.web.core.controller.BaseController;
import com.starry.module.system.api.dict.domain.qo.SysDictionaryDataPageQo;
import com.starry.module.system.api.dict.domain.qo.SysDictionaryDataQo;
import com.starry.module.system.api.dict.domain.vo.SysDictionaryDataDtlVo;
import com.starry.module.system.api.dict.domain.vo.SysDictionaryDataVo;
import com.starry.module.system.core.dict.service.SysDictionaryDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 系统字典内容
 *
 * @author xiaoke
 */
@Tag(name = "系统字典内容")
@RestController
@RequestMapping("/system/sysDictionaryData")
public class SysDictionaryDataController extends BaseController {

    private final SysDictionaryDataService sysDictionaryDataService;

    public SysDictionaryDataController(SysDictionaryDataService sysDictionaryDataService) {
        this.sysDictionaryDataService = sysDictionaryDataService;
    }

    /**
     * 分页查询
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "系统字典内容-分页查询")
    @GetMapping("sysDictionaryDataPage")
    public R<PageVo<SysDictionaryDataVo>> findPage(SysDictionaryDataPageQo pageQo) {
        return success(this.sysDictionaryDataService.page(pageQo));
    }

    /**
     * 根据字典类型获取字典数据列表
     *
     * @param dictType 字典类型
     * @return 字典数据列表
     */
    @Operation(summary = "系统字典内容-根据字典类型获取字典数据列表")
    @GetMapping("sysDictionaryDataByDictType/{dictType}")
    @TenantIgnore
    public R<List<SysDictionaryDataVo>> selectByDictType(@PathVariable("dictType") String dictType) {
        return success(this.sysDictionaryDataService.getByDictType(dictType));
    }

    /**
     * 详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "系统字典内容-详情")
    @GetMapping("sysDictionaryDataDetails/{id}")
    public R<SysDictionaryDataDtlVo> findById(@PathVariable("id") Long id) {
        return success(this.sysDictionaryDataService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysDictionaryDataQo 实体对象
     * @return 新增结果
     */
    @Operation(summary = "系统字典内容-新增")
    @PostMapping("sysDictionaryDataCreate")
    public R<Long> insert(@RequestBody @Validated SysDictionaryDataQo sysDictionaryDataQo) {
        return success(HttpStatus.HTTP_CREATED, this.sysDictionaryDataService.save(sysDictionaryDataQo));
    }

    /**
     * 修改数据
     *
     * @param sysDictionaryDataQo 实体对象
     * @return 修改结果
     */
    @Operation(summary = "系统字典内容-修改")
    @PostMapping("sysDictionaryDataUpdate")
    public R<Void> update(@RequestBody @Validated SysDictionaryDataQo sysDictionaryDataQo) {
        this.sysDictionaryDataService.updateById(sysDictionaryDataQo);
        return success();
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统字典内容-删除")
    @PostMapping("sysDictionaryDataRemove")
    public R<Void> delete(@RequestParam("idList") Set<Long> idList) {
        this.sysDictionaryDataService.removeByIds(idList);
        return success();
    }

    /**
     * 启用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统字典内容-启用")
    @PostMapping("sysDictionaryDataEnable")
    public R<Void> enable(@RequestParam("idList") Set<Long> idList) {
        this.sysDictionaryDataService.enable(idList);
        return success();
    }

    /**
     * 禁用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统字典内容-禁用")
    @PostMapping("sysDictionaryDataDisable")
    public R<Void> disable(@RequestParam("idList") Set<Long> idList) {
        this.sysDictionaryDataService.disable(idList);
        return success();
    }
}

